import java.awt.*;

import javax.swing.*;

public class CursorLayer extends JPanel {
	int w, h;
	int pos_x = 8;
	int pos_y = 5;
	Cursor cursor;
	String[] imageFile = { "cursor.png", "cursor2.png" };
	Image[] image = new Image[imageFile.length];

	public CursorLayer(Cursor cursor) {
		this.cursor = cursor;
		this.setFocusable(false);

		// Initialize images from their file names
		MediaTracker media = new MediaTracker(this);
		for (int i = 0; i < imageFile.length; i++) {
			image[i] = Toolkit.getDefaultToolkit().getImage(
					"graphics\\" + imageFile[i]);
			media.addImage(image[i], 0);
			try {
				media.waitForID(0);
			} catch (Exception e) {
			}
		}

	}

	public void paint(Graphics g) {
		this.setLocation(0, 0);
		w = 850;
		h = 550;
		this.setSize(w, h);
		this.setOpaque(false);
		// Draw cursor image

		int posx, posy;
		posx = -8 + cursor.getx();
		posy = -5 + cursor.gety();
		int destx = posx, desty = posy;

		if ((cursor.getdx() > -1) && (cursor.getdy() > -1)) {
			destx = cursor.getdx();
			desty = cursor.getdy();
		} else {
			try {
				destx = cursor.getSelected().getDestX();
				desty = cursor.getSelected().getDestY();
			} catch (Exception e) {
			}
		}
		if ((destx > -1) && (desty > -1)) {

			if ((destx - posx == 8) && (desty - posy == 5)) {

			} else {
				g.drawImage(image[1], (destx - posx) * 50, (desty - posy) * 50,
						this);
			}
		}
		g.drawImage(image[0], 8 * 50, 5 * 50, this);

	}
}
